import { PropertyKey } from "@/constants/Enums";
import { DiagramCustomizationManagementModel } from "../../DiagramCustomizationManagementModel";

export class DiagramMatrixConfigurationModel {
  rowElementIds: string[] = [];
  columnElementIds: string[] = [];
  relationCriteria = "";
  relationDirection: { label: string; value: string } | undefined = undefined;
  showElement: { label: string; value: string } | undefined = undefined;

  currentProjectId: string;
  isModelDisabled: boolean;

  constructor(public diagramCustomizationManagementModel: DiagramCustomizationManagementModel) {
    this.currentProjectId = diagramCustomizationManagementModel.queryParams.projectId;
    this.isModelDisabled = diagramCustomizationManagementModel.isModelDisabled;
  }

  getData() {
    return {
      [PropertyKey.DiagramMatrix_rowElementType]: this.rowElementIds.length ? this.rowElementIds : undefined,
      [PropertyKey.DiagramMatrix_columnElementType]: this.columnElementIds.length ? this.columnElementIds : undefined,
      [PropertyKey.DiagramMatrix_relationCriterion]: this.relationCriteria,
      [PropertyKey.DiagramMatrix_direction]: this.relationDirection,
      [PropertyKey.DiagramMatrix_showElements]: this.showElement
    };
  }

  async initData(matrixData) {
    if (matrixData) {
      if (matrixData[PropertyKey.DiagramMatrix_rowElementType] && matrixData[PropertyKey.DiagramMatrix_rowElementType].length) {
        this.rowElementIds = matrixData[PropertyKey.DiagramMatrix_rowElementType];
      }
      if (matrixData[PropertyKey.DiagramMatrix_columnElementType] && matrixData[PropertyKey.DiagramMatrix_columnElementType].length) {
        this.columnElementIds = matrixData[PropertyKey.DiagramMatrix_columnElementType];
      }
      if (matrixData[PropertyKey.DiagramMatrix_relationCriterion] && matrixData[PropertyKey.DiagramMatrix_relationCriterion].length) {
        this.relationCriteria = matrixData[PropertyKey.DiagramMatrix_relationCriterion];
      }
      if (matrixData[PropertyKey.DiagramMatrix_direction]) {
        this.relationDirection = matrixData[PropertyKey.DiagramMatrix_direction];
      }
      if (matrixData[PropertyKey.DiagramMatrix_showElements]) {
        this.showElement = matrixData[PropertyKey.DiagramMatrix_showElements];
      }
    }
  }
}
